<?php
/*
 * 登录model
*/
namespace app\system\model;
use think\Cache;
use \think\Model;
use \think\db;


class Login extends Base
{


    /***
     * 后台登陆
     * @param array $data
     * @return bool
     */
    public function checkLogin($data=[]){
        $user = session("user_id");
        if($user){
           return false;
        }else{
          $where = [
            "username"=>$data['username'],
            "password"=>md5($data['password'])
          ];
          $result = Db::name(self::$tb['sys_user'])->where($where)->field("id,name,username,phone,sys_role_id")->find();
          if($result){
            $permission = Db::name(self::$tb['sys_role_permission'])->alias("rp")->join("jun_sys_permission p","p.id=rp.sys_permission_id")->where("rp.sys_role_id",$result['sys_role_id'])->field("p.val")->select();
            //缓存所有的权限
            $arr = array_column($permission, 'val'); 
            set_cache("user_".$result['id'],$arr);
            session("user_id",$result);
            return $result;
          }else{
            return false;
          }
        }
    }
 

 

}
